package ttu.idu0080.ryhm103_logger;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class OrderBusinessProcessLogger {

	private static final String DATE_FORMAT = "yyyy.MM.dd HH:mm";
	private static final String LOGGER_FILE = "C:/Users/Henry/Desktop/bprocess_log.txt";

	public static synchronized void log(String message, boolean addTime)
			throws IOException {
		BufferedWriter writer = null;
		try {
			if (addTime) {
				message = new SimpleDateFormat(DATE_FORMAT).format(new Date())
						+ " " + message;
			}
			writer = new BufferedWriter(new FileWriter(LOGGER_FILE, true));
			writer.write(message + System.getProperty("line.separator"));
		} finally {
			if (writer != null)
				writer.close();
		}
	}
}
